package com.example.testsherlock1;

import android.graphics.drawable.*;
import android.os.*;
import android.widget.*;

import com.actionbarsherlock.app.*;
import com.actionbarsherlock.view.*;
import com.devspark.sidenavigation.*;
import com.devspark.sidenavigation.SideNavigationView.Mode;

public class MainActivity extends SherlockActivity implements
		ISideNavigationCallback {

//	public static final String EXTRA_TITLE = "com.devspark.sidenavigation.sample.extra.MTGOBJECT";
//	public static final String EXTRA_RESOURCE_ID = "com.devspark.sidenavigation.sample.extra.RESOURCE_ID";
//	public static final String EXTRA_MODE = "com.devspark.sidenavigation.sample.extra.MODE";
	

	private ImageView icon;
	private SideNavigationView sideNavigationView;
	private ActionBar actionBar;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

//		icon = (ImageView) findViewById(R.id.icon);
		sideNavigationView = (SideNavigationView) findViewById(R.id.side_navigation_view);
		sideNavigationView.setMenuItems(R.menu.side_navigation_menu);
		sideNavigationView.setMenuClickCallback(this);

//		if (getIntent().hasExtra(EXTRA_TITLE)) {
//			String title = getIntent().getStringExtra(EXTRA_TITLE);
//			int resId = getIntent().getIntExtra(EXTRA_RESOURCE_ID, 0);
//			setTitle(title);
//			icon.setImageResource(resId);
//			sideNavigationView
//					.setMode(getIntent().getIntExtra(EXTRA_MODE, 0) == 0 ? Mode.LEFT
//							: Mode.RIGHT);
//		}

		actionBar=getSupportActionBar();
		actionBar.setBackgroundDrawable(new ColorDrawable(0xffffff00));
		actionBar.setTitle("How Do You Feel?");
		actionBar.setSubtitle("I'm fine,thank you");
		actionBar.setLogo(R.drawable.holo_dark_action_side_navigation);
		actionBar.setHomeButtonEnabled(true);
		actionBar.setDisplayHomeAsUpEnabled(true);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub

		getSupportMenuInflater().inflate(R.menu.activity_main, menu);
		if (sideNavigationView.getMode() == Mode.RIGHT) {
			menu.findItem(R.id.mode_right).setChecked(true);
		} else {
			menu.findItem(R.id.mode_left).setChecked(true);
		}
		
		menu.add("CROP_ICON").setIcon(R.drawable.ic_launcher)
						.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
		menu.add("CROP_TITLE").setTitle("CROP")
							  .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
		menu.add("SEND_ICON").setIcon(R.drawable.ic_launcher)
						.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
		menu.add("SEND_TITLE").setTitle("SEND")
							  .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			sideNavigationView.toggleMenu();
			break;
		case R.id.mode_left:
			item.setChecked(true);
			sideNavigationView.setMode(Mode.LEFT);
			break;
		case R.id.mode_right:
			item.setChecked(true);
			sideNavigationView.setMode(Mode.RIGHT);
			break;
		default:
			return super.onOptionsItemSelected(item);
		}
		return true;
	}

	@Override
	public void onSideNavigationItemClick(int itemId) {
		// TODO Auto-generated method stub
		switch (itemId) {
		case R.id.side_navigation_menu_item1:
			setTitle("menu1");
			icon.setImageResource(R.drawable.ic_launcher);
			break;
		case R.id.side_navigation_menu_item2:
			setTitle("menu2");
			icon.setImageResource(R.drawable.ic_launcher);
			break;
		case R.id.side_navigation_menu_item3:
			setTitle("menu3");
			icon.setImageResource(R.drawable.ic_launcher);
			break;
		case R.id.side_navigation_menu_item4:
			setTitle("menu4");
			icon.setImageResource(R.drawable.ic_launcher);
			break;
		case R.id.side_navigation_menu_item5:
			setTitle("menu5");
			icon.setImageResource(R.drawable.ic_launcher);
			break;
		default:
			break;
		}

	}

}
